<template>
    <div class="satus" v-show="isShow">
        <div id="plants-chart"></div>
    </div>
</template>

<script setup>
import * as echarts from "echarts";

var chart = undefined

const isShow = ref(false)

const props = defineProps({
    dataset: Array,
    title: String
})


const drawChart = () => {
    chart = chart || echarts.init(document.getElementById("plants-chart"));
    chart.clear()
    const option = {
        title: {
            text: props.title,
            left: 'center'
        },
        tooltip: {
            trigger: 'item'
        },
        legend: {
            orient: 'vertical',
            left: 'right'
        },
        series: [
            {
                type: 'pie',
                radius: '50%',
                data: props.dataset,
                emphasis: {
                    itemStyle: {
                        shadowBlur: 10,
                        shadowOffsetX: 0,
                        shadowColor: 'rgba(0, 0, 0, 0.5)'
                    }
                }
            }
        ]
    };

    chart.setOption(option);
}

defineExpose({
    drawChart,
    isShow
})

</script>

<style lang="scss" scoped>
#plants-chart {
    width: 900px;
    height: 250px;
}
</style>